Skip to content

Host core: the projection's selectors and selection without React - #149

Merged
agorischek merged 2 commits into
mainfrom
store-selectors
Nov 21, 2026
Merged

agorischek merged 2 commits into
mainfrom
store-selectors

Conversation

@agorischek

Copy link
Copy Markdown
Collaborator

Step 4 of the headless store design (docs/design/proposals/headless-store.md), stacked on #148.

  • Selectors. createRowFilter (rows, scope, counts, what Changes hides, the filter payload) and createRendererPayloads (init, environment, progress, endpoints, a static diff's progress) are framework-free.
    • They're built from one-slot memos (projection/memo.ts), so each result keeps its identity while its inputs do, as the React memos did.
    • The init still isn't remade for a theme or motion change, and the static diff's highlighting latch is closure state instead of a ref.
  • Selection. It's now pure functions: selectionOf, selectedPaths, selectedTarget, targetSelection, plus createSelectionReport for onSelectionChange.
  • Interaction. The pinned target, hover and anchors are one reducer (projection/interaction.ts) that useProjection runs with useReducer.
    • An event that changes nothing keeps the state, so a repeated anchor or hover doesn't re-render.
    • The stage binding sends anchored and frameReplaced events instead of calling setAnchors updaters.
  • Status events. Host core: tell hosts when the renderer is ready and when the frames have painted #122's events are told by createStatusEvents, which useStatusEvents calls after each commit.
  • The hooks keep only React's part: one selector instance per component, and the effects that report. ProjectionController is unchanged, and nothing new is exported; the store composes these in step 5.
  • The design note's step 4 says so. check:machines baseline is lowered by one, since payloads.ts no longer holds a ref latch.
  • Node tests (test/store-selectors.test.mjs) cover selector identity, the payloads' rules, the reducer, the selection helpers and the status events, without React.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active findings show that in-place mutations can suppress required init updates and alter earlier payloads, while abandoned renders can trigger unnecessary reinitialization and filtering updates through shared caches.

2 open issues
What changed in this PR

Implements step 4 of the headless-store design by extracting selector, selection, and status-reporting logic from React hooks, preparing it for store composition without changing ProjectionController.

Changes:

  • Adds memoized selectors for row filtering and renderer payloads.
  • Extracts selection helpers, an interaction reducer, and status-event reporting.
  • Adds Node tests and updates the design note and machine-check baseline.
File Description
tools/​scripts/​check-machines/​baseline.json Removes the payload ref-latch baseline entry.
packages/​host/​core/​test/​store-selectors.test.mjs Tests selectors, interaction, selection, and status events.
packages/​host/​core/​src/​projection/​use-projection.ts Integrates the interaction reducer.
packages/​host/​core/​src/​projection/​stage-binding.ts Dispatches anchor and frame-replacement events.
packages/​host/​core/​src/​projection/​selection.ts Extracts selection helpers and change reporting.
packages/​host/​core/​src/​projection/​payloads.ts Extracts the memoized renderer-payload selector.
packages/​host/​core/​src/​projection/​paint.ts Extracts framework-independent status-event reporting.
packages/​host/​core/​src/​projection/​memo.ts Adds shared one-slot memoization helpers.
packages/​host/​core/​src/​projection/​interaction.ts Adds the pinned-target, hover, and anchor reducer.
packages/​host/​core/​src/​projection/​filtering.ts Extracts the memoized row-filter selector.
docs/​design/​proposals/​headless-store.md Documents step 4 and clarifies step 5 integration.

Review effort: Balanced

Base automatically changed from playback-store to main November 21, 2026 20:54
The row filter and the renderer payloads become framework-free selectors
(createRowFilter, createRendererPayloads), built from one-slot memos so each
result keeps its identity while its inputs do. Selection is pure functions,
and the pinned target, hover and anchors are one reducer (interaction) that
useProjection runs with useReducer. The renderer status and painted events
are told by createStatusEvents. The hooks keep only React's part. Step 4 of
the headless store design.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ed by JSON are copies

Each memo compares first with the values last committed, then with the last
computed, and computing never replaces what was committed: a render React
throws away no longer evicts the committed results, so a still-shown subject
keeps its init and rows. The hooks commit after each committed render; a
vanilla host commits after each read. byValue keeps a parsed copy, so a focus
or kinds changed in place is a new init, and payloads share nothing with the
host's objects.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek merged commit ce54f84 into main Nov 21, 2026
55 checks passed
@agorischek
agorischek deleted the store-selectors branch November 21, 2026 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants